package zhongbo.java.air.airflightpath.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.airflightpath.config.RedisListenerConfig;
import zhongbo.java.air.airflightpath.listener.RedisLogChanelPublisher;
import zhongbo.java.air.airflightpath.model.AirFlightPath;
import zhongbo.java.air.airflightpath.service.IAirFightPathService;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;

import javax.validation.Valid;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/flightPath")
@Api(tags = "航迹数据接口")
public class FlightPathController {

    @Autowired
    private IAirFightPathService<AirFlightPath> airFightPathService;

    @Autowired
    private RedisLogChanelPublisher redisLogChanelPublisher;

    @GetMapping("/queryByPage")
    @ApiOperation("分页查询")
    public ResultVo<PageVo<AirFlightPath>> queryByPage(Integer page, Integer pageSize) {
        PageVo<AirFlightPath> airFlightPathPageVo = airFightPathService.queryByPage(page, pageSize);
        redisLogChanelPublisher.publishMessage(RedisListenerConfig.LOG_CHANEL,"分页查询 ->>> " + airFlightPathPageVo);
        return ResultVo.ok(airFlightPathPageVo);
    }

//    @GetMapping("/queryByPageIcao")
//    @ApiOperation("分页查询根据Icao")

    @GetMapping("findPage")
    @ApiOperation("分页查询列表")
    public ResultVo<PageVo<AirFlightPath>> queryByPage(Integer page, Integer pageSize
            , String icao, String startTime, String endTime
            , String keyword, String fields
            , String oderByField, Boolean orderByAsc) {
        PageVo<AirFlightPath> airFlightPathPageVo = airFightPathService.queryByPageTime(page, pageSize
                , icao, startTime, endTime
                , keyword, fields, oderByField, orderByAsc);
        redisLogChanelPublisher.publishMessage(RedisListenerConfig.LOG_CHANEL,"分页查询 ->>> "+ airFlightPathPageVo);
        return ResultVo.ok(airFlightPathPageVo);
    }

//    @GetMapping("/selectById/{id}")
//    @ApiOperation("根据id查询飞行轨迹信息")

    @GetMapping("findOne")
    @ApiOperation("查询一条")
    public ResultVo<AirFlightPath> queryById(String entityId) {
        AirFlightPath airFlightPath = airFightPathService.queryById(entityId);
        redisLogChanelPublisher.publishMessage(RedisListenerConfig.LOG_CHANEL,"根据id查询飞行轨迹 ->>> " + airFlightPath);
        return ResultVo.ok(airFlightPath);
    }

    @PostMapping("/add")
    @ApiOperation("添加飞行轨迹")
    public ResultVo<AirFlightPath> add(@RequestBody @Valid AirFlightPath airFlightPath) {
        AirFlightPath insert = airFightPathService.insert(airFlightPath);
        redisLogChanelPublisher.publishMessage(RedisListenerConfig.LOG_CHANEL,"添加飞行轨迹 ->>> " + insert);
        return ResultVo.ok(insert);
    }

//    @PutMapping("/edit")
//    @ApiOperation("修改飞行轨迹")

    @PostMapping("edit")
    @ApiOperation("修改")
    public ResultVo<AirFlightPath> edit(@RequestBody @Valid AirFlightPath airFlightPath) {
        AirFlightPath update = airFightPathService.update(airFlightPath);
//        redisLogChanelPublisher.publishMessage(RedisListenerConfig.LOG_CHANEL,"修改飞行轨迹 ->>>" + airFlightPath);
        return ResultVo.ok(update);
    }


//    @DeleteMapping("/deleteById/{id}")
//    @ApiOperation("根据id删除飞行轨迹")
    @GetMapping("delete")
    @ApiOperation("删除")
    public ResultVo<String> deleteById(String entityId) {
        airFightPathService.deleteById(entityId);
        redisLogChanelPublisher.publishMessage(RedisListenerConfig.LOG_CHANEL,"根据id删除飞行轨迹 ->>> id：" +  entityId);
        return ResultVo.ok("删除成功");
    }
}
